package com.code.day02;

import com.code.day02.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.Connection;
import java.sql.SQLException;

public class Shiwu {
    public static void main(String[] args) throws Exception {
        QueryRunner queryRunner = new QueryRunner();
        Connection connection = DruidUtils.getConnection();
        try{
            connection.setAutoCommit(false);
            String sql = "update category set cname = ? where cid = ?";
            queryRunner.update(connection,sql,"wxss",1);
            //System.out.println(1 / 0);
            connection.commit();
            System.out.println("Success");
        }catch(Exception e){
            try{
                connection.rollback();
                System.out.println("Fail");
            }catch (SQLException e1){
                e1.printStackTrace();
            }
            e.printStackTrace();
        }finally{
            connection.close();
        }
    }
}
